<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>cgebd2.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="CGEBD2.1"></a><a href="cgebd2.f.html#CGEBD2.1">CGEBD2</a>( M, N, A, LDA, D, E, TAUQ, TAUP, WORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, LDA, M, N
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      REAL               D( * ), E( * )
      COMPLEX            A( LDA, * ), TAUP( * ), TAUQ( * ), WORK( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="CGEBD2.18"></a><a href="cgebd2.f.html#CGEBD2.1">CGEBD2</a> reduces a complex general m by n matrix A to upper or lower
</span><span class="comment">*</span><span class="comment">  real bidiagonal form B by a unitary transformation: Q' * A * P = B.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If m &gt;= n, B is upper bidiagonal; if m &lt; n, B is lower bidiagonal.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  M       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of rows in the matrix A.  M &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of columns in the matrix A.  N &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  A       (input/output) COMPLEX array, dimension (LDA,N)
</span><span class="comment">*</span><span class="comment">          On entry, the m by n general matrix to be reduced.
</span><span class="comment">*</span><span class="comment">          On exit,
</span><span class="comment">*</span><span class="comment">          if m &gt;= n, the diagonal and the first superdiagonal are
</span><span class="comment">*</span><span class="comment">            overwritten with the upper bidiagonal matrix B; the
</span><span class="comment">*</span><span class="comment">            elements below the diagonal, with the array TAUQ, represent
</span><span class="comment">*</span><span class="comment">            the unitary matrix Q as a product of elementary
</span><span class="comment">*</span><span class="comment">            reflectors, and the elements above the first superdiagonal,
</span><span class="comment">*</span><span class="comment">            with the array TAUP, represent the unitary matrix P as
</span><span class="comment">*</span><span class="comment">            a product of elementary reflectors;
</span><span class="comment">*</span><span class="comment">          if m &lt; n, the diagonal and the first subdiagonal are
</span><span class="comment">*</span><span class="comment">            overwritten with the lower bidiagonal matrix B; the
</span><span class="comment">*</span><span class="comment">            elements below the first subdiagonal, with the array TAUQ,
</span><span class="comment">*</span><span class="comment">            represent the unitary matrix Q as a product of
</span><span class="comment">*</span><span class="comment">            elementary reflectors, and the elements above the diagonal,
</span><span class="comment">*</span><span class="comment">            with the array TAUP, represent the unitary matrix P as
</span><span class="comment">*</span><span class="comment">            a product of elementary reflectors.
</span><span class="comment">*</span><span class="comment">          See Further Details.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDA     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array A.  LDA &gt;= max(1,M).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  D       (output) REAL array, dimension (min(M,N))
</span><span class="comment">*</span><span class="comment">          The diagonal elements of the bidiagonal matrix B:
</span><span class="comment">*</span><span class="comment">          D(i) = A(i,i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  E       (output) REAL array, dimension (min(M,N)-1)
</span><span class="comment">*</span><span class="comment">          The off-diagonal elements of the bidiagonal matrix B:
</span><span class="comment">*</span><span class="comment">          if m &gt;= n, E(i) = A(i,i+1) for i = 1,2,...,n-1;
</span><span class="comment">*</span><span class="comment">          if m &lt; n, E(i) = A(i+1,i) for i = 1,2,...,m-1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAUQ    (output) COMPLEX array dimension (min(M,N))
</span><span class="comment">*</span><span class="comment">          The scalar factors of the elementary reflectors which
</span><span class="comment">*</span><span class="comment">          represent the unitary matrix Q. See Further Details.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  TAUP    (output) COMPLEX array, dimension (min(M,N))
</span><span class="comment">*</span><span class="comment">          The scalar factors of the elementary reflectors which
</span><span class="comment">*</span><span class="comment">          represent the unitary matrix P. See Further Details.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  WORK    (workspace) COMPLEX array, dimension (max(M,N))
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0: successful exit 
</span><span class="comment">*</span><span class="comment">          &lt; 0: if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The matrices Q and P are represented as products of elementary
</span><span class="comment">*</span><span class="comment">  reflectors:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If m &gt;= n,
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Q = H(1) H(2) . . . H(n)  and  P = G(1) G(2) . . . G(n-1)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Each H(i) and G(i) has the form:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where tauq and taup are complex scalars, and v and u are complex
</span><span class="comment">*</span><span class="comment">  vectors; v(1:i-1) = 0, v(i) = 1, and v(i+1:m) is stored on exit in
</span><span class="comment">*</span><span class="comment">  A(i+1:m,i); u(1:i) = 0, u(i+1) = 1, and u(i+2:n) is stored on exit in
</span><span class="comment">*</span><span class="comment">  A(i,i+2:n); tauq is stored in TAUQ(i) and taup in TAUP(i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  If m &lt; n,
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Q = H(1) H(2) . . . H(m-1)  and  P = G(1) G(2) . . . G(m)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Each H(i) and G(i) has the form:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     H(i) = I - tauq * v * v'  and G(i) = I - taup * u * u'
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where tauq and taup are complex scalars, v and u are complex vectors;
</span><span class="comment">*</span><span class="comment">  v(1:i) = 0, v(i+1) = 1, and v(i+2:m) is stored on exit in A(i+2:m,i);
</span><span class="comment">*</span><span class="comment">  u(1:i-1) = 0, u(i) = 1, and u(i+1:n) is stored on exit in A(i,i+1:n);
</span><span class="comment">*</span><span class="comment">  tauq is stored in TAUQ(i) and taup in TAUP(i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  The contents of A on exit are illustrated by the following examples:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  m = 6 and n = 5 (m &gt; n):          m = 5 and n = 6 (m &lt; n):
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">    (  d   e   u1  u1  u1 )           (  d   u1  u1  u1  u1  u1 )
</span><span class="comment">*</span><span class="comment">    (  v1  d   e   u2  u2 )           (  e   d   u2  u2  u2  u2 )
</span><span class="comment">*</span><span class="comment">    (  v1  v2  d   e   u3 )           (  v1  e   d   u3  u3  u3 )
</span><span class="comment">*</span><span class="comment">    (  v1  v2  v3  d   e  )           (  v1  v2  e   d   u4  u4 )
</span><span class="comment">*</span><span class="comment">    (  v1  v2  v3  v4  d  )           (  v1  v2  v3  e   d   u5 )
</span><span class="comment">*</span><span class="comment">    (  v1  v2  v3  v4  v5 )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  where d and e denote diagonal and off-diagonal elements of B, vi
</span><span class="comment">*</span><span class="comment">  denotes an element of the vector defining H(i), and ui an element of
</span><span class="comment">*</span><span class="comment">  the vector defining G(i).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      COMPLEX            ZERO, ONE
      PARAMETER          ( ZERO = ( 0.0E+0, 0.0E+0 ),
     $                   ONE = ( 1.0E+0, 0.0E+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            I
      COMPLEX            ALPHA
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           <a name="CLACGV.136"></a><a href="clacgv.f.html#CLACGV.1">CLACGV</a>, <a name="CLARF.136"></a><a href="clarf.f.html#CLARF.1">CLARF</a>, <a name="CLARFG.136"></a><a href="clarfg.f.html#CLARFG.1">CLARFG</a>, <a name="XERBLA.136"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          CONJG, MAX, MIN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
      IF( M.LT.0 ) THEN
         INFO = -1
      ELSE IF( N.LT.0 ) THEN
         INFO = -2
      ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
         INFO = -4
      END IF
      IF( INFO.LT.0 ) THEN
         CALL <a name="XERBLA.154"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="CGEBD2.154"></a><a href="cgebd2.f.html#CGEBD2.1">CGEBD2</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span>      IF( M.GE.N ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Reduce to upper bidiagonal form
</span><span class="comment">*</span><span class="comment">
</span>         DO 10 I = 1, N
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Generate elementary reflector H(i) to annihilate A(i+1:m,i)
</span><span class="comment">*</span><span class="comment">
</span>            ALPHA = A( I, I )
            CALL <a name="CLARFG.167"></a><a href="clarfg.f.html#CLARFG.1">CLARFG</a>( M-I+1, ALPHA, A( MIN( I+1, M ), I ), 1,
     $                   TAUQ( I ) )
            D( I ) = ALPHA
            A( I, I ) = ONE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Apply H(i)' to A(i:m,i+1:n) from the left
</span><span class="comment">*</span><span class="comment">
</span>            IF( I.LT.N )
     $         CALL <a name="CLARF.175"></a><a href="clarf.f.html#CLARF.1">CLARF</a>( <span class="string">'Left'</span>, M-I+1, N-I, A( I, I ), 1,
     $                     CONJG( TAUQ( I ) ), A( I, I+1 ), LDA, WORK )
            A( I, I ) = D( I )
<span class="comment">*</span><span class="comment">
</span>            IF( I.LT.N ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Generate elementary reflector G(i) to annihilate
</span><span class="comment">*</span><span class="comment">              A(i,i+2:n)
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLACGV.184"></a><a href="clacgv.f.html#CLACGV.1">CLACGV</a>( N-I, A( I, I+1 ), LDA )
               ALPHA = A( I, I+1 )
               CALL <a name="CLARFG.186"></a><a href="clarfg.f.html#CLARFG.1">CLARFG</a>( N-I, ALPHA, A( I, MIN( I+2, N ) ),
     $                      LDA, TAUP( I ) )
               E( I ) = ALPHA
               A( I, I+1 ) = ONE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Apply G(i) to A(i+1:m,i+1:n) from the right
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLARF.193"></a><a href="clarf.f.html#CLARF.1">CLARF</a>( <span class="string">'Right'</span>, M-I, N-I, A( I, I+1 ), LDA,
     $                     TAUP( I ), A( I+1, I+1 ), LDA, WORK )
               CALL <a name="CLACGV.195"></a><a href="clacgv.f.html#CLACGV.1">CLACGV</a>( N-I, A( I, I+1 ), LDA )
               A( I, I+1 ) = E( I )
            ELSE
               TAUP( I ) = ZERO
            END IF
   10    CONTINUE
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Reduce to lower bidiagonal form
</span><span class="comment">*</span><span class="comment">
</span>         DO 20 I = 1, M
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Generate elementary reflector G(i) to annihilate A(i,i+1:n)
</span><span class="comment">*</span><span class="comment">
</span>            CALL <a name="CLACGV.209"></a><a href="clacgv.f.html#CLACGV.1">CLACGV</a>( N-I+1, A( I, I ), LDA )
            ALPHA = A( I, I )
            CALL <a name="CLARFG.211"></a><a href="clarfg.f.html#CLARFG.1">CLARFG</a>( N-I+1, ALPHA, A( I, MIN( I+1, N ) ), LDA,
     $                   TAUP( I ) )
            D( I ) = ALPHA
            A( I, I ) = ONE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">           Apply G(i) to A(i+1:m,i:n) from the right
</span><span class="comment">*</span><span class="comment">
</span>            IF( I.LT.M )
     $         CALL <a name="CLARF.219"></a><a href="clarf.f.html#CLARF.1">CLARF</a>( <span class="string">'Right'</span>, M-I, N-I+1, A( I, I ), LDA,
     $                     TAUP( I ), A( I+1, I ), LDA, WORK )
            CALL <a name="CLACGV.221"></a><a href="clacgv.f.html#CLACGV.1">CLACGV</a>( N-I+1, A( I, I ), LDA )
            A( I, I ) = D( I )
<span class="comment">*</span><span class="comment">
</span>            IF( I.LT.M ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Generate elementary reflector H(i) to annihilate
</span><span class="comment">*</span><span class="comment">              A(i+2:m,i)
</span><span class="comment">*</span><span class="comment">
</span>               ALPHA = A( I+1, I )
               CALL <a name="CLARFG.230"></a><a href="clarfg.f.html#CLARFG.1">CLARFG</a>( M-I, ALPHA, A( MIN( I+2, M ), I ), 1,
     $                      TAUQ( I ) )
               E( I ) = ALPHA
               A( I+1, I ) = ONE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Apply H(i)' to A(i+1:m,i+1:n) from the left
</span><span class="comment">*</span><span class="comment">
</span>               CALL <a name="CLARF.237"></a><a href="clarf.f.html#CLARF.1">CLARF</a>( <span class="string">'Left'</span>, M-I, N-I, A( I+1, I ), 1,
     $                     CONJG( TAUQ( I ) ), A( I+1, I+1 ), LDA,
     $                     WORK )
               A( I+1, I ) = E( I )
            ELSE
               TAUQ( I ) = ZERO
            END IF
   20    CONTINUE
      END IF
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="CGEBD2.248"></a><a href="cgebd2.f.html#CGEBD2.1">CGEBD2</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
